package com.liusu.file.config;

import com.liusu.file.utils.CustomMinioClient;
import io.minio.MinioAsyncClient;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建Minio客户端
 */
@Configuration
@Data
public class MinioConfig {
    @Value("${minio.accessKey}")
    private String accessKey;
    @Value("${minio.secretKey}")
    private String secretKey;
    @Value("${minio.url}")
    private String url;

    @Value("${minio.bucketName}")
    private String bucketName;

    /**
     * 配置minio连接客户端
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .credentials(accessKey, secretKey)
                .endpoint(url)
                .build();
    }

    /**
     * 配置用于分片上传的Minio连接客户端
     */
    @Bean
    public CustomMinioClient customMinioClient() {
        MinioAsyncClient asyncClient = MinioAsyncClient.builder()
                .endpoint(url)
                .credentials(accessKey, secretKey)
                .build();
        return new CustomMinioClient(asyncClient);
    }
}